package org.ccu.servlet;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.ccu.dao.BuildingDAO;
import org.ccu.dao.CommentDAO;
import org.ccu.vo.Building;
import org.ccu.vo.Comment;

/**
 * Servlet implementation class IniServlet
 */
public class CommentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public CommentServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		if(request.getParameter("buildingid")!=null){
			request.getSession().setAttribute("buildingid", request.getParameter("buildingid"));
		}
		doPost(request,response);
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		List<Comment> s = CommentDAO.getComment(""+request.getSession().getAttribute("buildingid"));
		List<Building> i = BuildingDAO.getBuildingByID(""+request.getSession().getAttribute("buildingid"));
		request.setAttribute("lz",i);
		request.setAttribute("titles", s);

		request.getRequestDispatcher("/pages/building.jsp").forward(
				request, response);

	}

}
